<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>添加/修改插件</title>
<link href="__PUBLIC__/admin/css/xc.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/xc.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.js"></script> 
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.admin.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/common-1.0.js"></script> 
</head>
<body>
<div class="pd-20">
  <div id="tab-system" class="HuiTab">
    <form action="" method="post" class="form form-horizontal" id="myform">
      <div class="tabCon">
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>插件名称：</label>
          <div class="formControls col-8">
            <input type="text" id="pname" name="pname" value="{$re.pl_name}" class="input-text">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>唯一标识：</label>
          <div class="formControls col-8">
            <input type="text" id="pcode" name="pcode" value="{$re.pl_code}" class="input-text">
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>是否启用：</label>
          <div class="formControls col-8 skin-minimal">
            <div class="radio-box"><input type="radio" id="state1" name="state" value="1" <if condition="($re[pl_state] eq 1)">checked</if>><label for="state1">开启</label></div>
            <div class="radio-box"><input type="radio" id="state2" name="state" value="2" <if condition="($re[pl_state] eq 2)">checked</if>><label for="state2">关闭</label></div>
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>插件图片：</label>
          <div class="formControls col-6">
            <span class="btn-upload form-group">
              <input class="input-text upload-url" type="text" id="bimgurl" name="pimg" value="{$re.pl_img}" readonly style="width:200px" placeholder="请上传大小为180X60像素图片">
              <input id="file_upload" name="file_upload" type="file" multiple value=""/>
            </span><br/><font color="#f00">*请上传宽度180X高度60像素图片</font>
          </div>
          <img id="bimg" src="__UPLOAD__/{$re.pl_img|default='img/no_image.jpg'}" style="width:140px; height:42px; margin-left: -4%; float: left">
        </div>
        <if condition="($re[pl_id] eq '')">
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>表单参数：</label>
          <div class="formControls col-10">
            <span class="select-box col-3" style="width:25%;margin-right:6px">
              <select name="fo_type[]" class="select valid" size="1">
               <option value="">请选择配置类型</option>
               <option value="text">文本框[text]</option>
               <option value="radio">单选按钮[radio]</option>
               <option value="select">下拉列表[select]</option>
             </select>
		    </span>
           <span class="col-3" style="margin-right:6px"><input type="text" name="fo_title[]" placeholder="表单标题title" class="input-text"></span>
           <span class="col-3" style="margin-right:6px"><input type="text" name="fo_name[]" placeholder="表单名称name" class="input-text"></span>
           <span class="col-1 mt-5"><i class="Hui-iconfont" style="cursor:pointer" onClick="add()"></i></span>
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-2"></label>
          <div class="formControls col-8">
            <textarea name="fo_area[]" placeholder="请输入配置值,没有请留空,分隔符为英文&quot;,&quot;" class="textarea" style="height: 60px"></textarea>
          </div>
        </div>
        <else />
        <volist name="reForm" id="vo" offset="0" length='1'>
        <div class="row cl">
          <label class="form-label col-2"><span class="c-red">*</span>表单参数：</label>
          <div class="formControls col-10">
            <span class="select-box col-3" style="width:25%;margin-right:6px">
              <select name="fo_type[]" class="select valid" size="1">
               <option value="">请选择配置类型</option>
               <option value="text" <if condition="($vo[fo_type] eq 'text')">selected</if>>文本框[text]</option>
               <option value="radio" <if condition="($vo[fo_type] eq 'radio')">selected</if>>单选按钮[radio]</option>
               <option value="select" <if condition="($vo[fo_type] eq 'select')">selected</if>>下拉列表[select]</option>
             </select>
		    </span>
           <span class="col-3" style="margin-right:6px"><input type="text" name="fo_title[]" value="{$vo.fo_title}" placeholder="表单标题title" class="input-text"></span>
           <span class="col-3" style="margin-right:6px"><input type="text" name="fo_name[]" value="{$vo.fo_name}" placeholder="表单名称name" class="input-text"></span>
           <span class="col-1 mt-5"><i class="Hui-iconfont" style="cursor:pointer" onClick="add()"></i></span>
          </div>
        </div>
        <div class="row cl">
          <label class="form-label col-2"></label>
          <div class="formControls col-8">
            <textarea name="fo_area[]" placeholder="请输入配置值,没有请留空,分隔符为英文&quot;,&quot;" class="textarea" style="height: 60px"><volist name="vo.fo_area" id="vv">{$vv},</volist></textarea>
          </div>
        </div>
        </volist>
        </if>
        <div class="add">
          <volist name="reForm" id="vo" offset="1">
            <div class="row cl">
              <label class="form-label col-2"><span class="c-red">*</span>表单参数：</label>
              <div class="formControls col-10">
                <span class="select-box col-3" style="width:25%;margin-right:6px">
                  <select name="fo_type[]" class="select valid" size="1">
                   <option value="">请选择配置类型</option>
                   <option value="text" <if condition="($vo[fo_type] eq 'text')">selected</if>>文本框[text]</option>
                   <option value="radio" <if condition="($vo[fo_type] eq 'radio')">selected</if>>单选按钮[radio]</option>
                   <option value="select" <if condition="($vo[fo_type] eq 'select')">selected</if>>下拉列表[select]</option>
                 </select>
                </span>
               <span class="col-3" style="margin-right:6px"><input type="text" name="fo_title[]" value="{$vo.fo_title}" placeholder="表单标题title" class="input-text"></span>
               <span class="col-3" style="margin-right:6px"><input type="text" name="fo_name[]" value="{$vo.fo_name}" placeholder="表单名称name" class="input-text"></span>
               <span class="col-1 mt-5"><i class="Hui-iconfont" style="cursor:pointer" onClick="del(this)"></i></span>
              </div>
            </div>
            <div class="row cl">
              <label class="form-label col-2"></label>
              <div class="formControls col-8">
                <textarea name="fo_area[]" placeholder="请输入配置值,没有请留空,分隔符为英文&quot;,&quot;" class="textarea" style="height: 60px"><volist name="vo.fo_area" id="vv">{$vv},</volist></textarea>
              </div>
            </div>
          </volist>
        </div>
        <div class="row cl">
          <input type="hidden" name="id" value="{$re.pl_id}">
          <div class="col-10 col-offset-2">
      		<button type="button" id="sub" name="sub" class="btn btn-primary radius" onClick="checkSubmit()"><i class='Hui-iconfont'>&#xe632;</i>&nbsp;保存</button>
            <input class="btn btn-default radius" type="button" onClick="layer_close();" value="取消"/>
          </div>
		</div>
      </div>
    </form>
  </div>
</div>
<script type="text/javascript">
//按回车件触发提交
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){ // enter 键
		checkSubmit();
	}
}; 
//提交数据
function checkSubmit(){
	var pname = $.trim($('#pname').val());
	var pcode = $.trim($('#pcode').val());
	var state = $('input:radio:checked').val();
	var bimgs = $.trim($('#bimgurl').val());
	if(pname == ''){
		layer.msg('插件名称不能为空', {icon: 2});
		return false;
	}if(pcode == ''){
		layer.msg('唯一标识不能为空!', {icon: 2});
		return false;
	}if(typeof(state) == "undefined"){
		layer.msg('启用状态未选择!', {icon: 2});
		return false;
	}if(bimgs == ''){
		layer.msg('缩略图不能为空!', {icon: 2});
		return false;
	}
	$.ajax({
		type : 'post',
		url : '__MODULE__/Plugin/plugAddEdit',
		data : $("#myform").serialize(),
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				layer.msg(res.msg,{icon:1},function(){
					// 先获取窗口索引，才能关闭窗口  
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
			   window.parent.location.reload(); //刷新父页面
			}else{
				layer.msg(res.msg, {icon: 2});
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.alert('网络失败，请刷新页面后重试',{icon:2});
		}
	})
}
function add(){
var html = 
  '<div class="row cl">'+
    '<label class="form-label col-2"></label>'+
	  '<div class="formControls col-10">'+
		'<span class="select-box col-3" style="width:25%;margin-right:6px">'+
		  '<select name="fo_type[]" class="select valid" size="1">'+
		    '<option value="">请选择配置类型</option>'+
		    '<option value="text">文本框[text]</option>'+
		    '<option value="radio">单选按钮[radio]</option>'+
		    '<option value="select">下拉列表[select]</option>'+
		  '</select>'+
	    '</span>'+
		'<span class="col-3" style="margin-right:6px"><input type="text" name="fo_title[]" placeholder="表单标题title" class="input-text"></span>'+
	    '<span class="col-3" style="margin-right:6px"><input type="text" name="fo_name[]" placeholder="表单名称name" class="input-text"></span>'+
	    '<span class="col-1"><i class="Hui-iconfont" style="cursor:pointer" onClick="del(this)"></i></span>'+
	  '</div>'+
	'</div>'+
	'<div class="row cl"><label class="form-label col-2"></label>'+
	  '<div class="formControls col-8"><textarea name="fo_area[]" placeholder="请输入配置值,没有请留空,分隔符为英文&quot;,&quot;" class="textarea" style="height: 60px"></textarea></div>'+
	'</div>'
;
$(".add").append(html);
}
function del(obj){
	$(obj).parent().parent().parent().next().remove();
	$(obj).parent().parent().parent().remove();
	
}
</script>
<!-- 图片上传 -->
<style type="text/css">
#file_upload{ float:right}
#file_upload-queue{ display:none}
</style>
<link href="__PUBLIC__/lib/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/lib/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript"> 
$(function() {
	$('#file_upload').uploadify({
        'swf'      : '__PUBLIC__/lib/uploadify/uploadify.swf',
        'uploader' : '__MODULE__/Uploader/setupFile?id=plug',
 		'buttonText' : '插件图片',
        'onUploadSuccess' : function(file, data, response) {
			$('#bimg').attr('src','__UPLOAD__/'+ data);
			$('#bimgurl').val(data);
        },
    });

});
</script>
<!-- 图片上传 -->
<!-- 单选 复选框 -->
<link href="__PUBLIC__/lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/lib/icheck/jquery.icheck.min.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});
</script>
<!-- 单选 复选框 -->
</body>
</html>